<%@ page language="java" pageEncoding="UTF-8"%>

<script type="text/javascript">
var detailValidator;

var editAction = "${param.action}";

function selectOrganization() {
	$.openDialog("#dialog",
			{height:350,
			width:300,
			minHeight:350,
			minWidth:300,
			loadPage:ctx+"/biz/system/organ/query.jsp",
			title:"选择组织机构"},
			function(data) {
				$("#userOrgan").data("id",data.data("id"));
				$("#userOrgan").val(data.data("name"));
			});
}

function saveDetail() {
	if (!detailValidator.form()) {
		return;
	}
	doSaveDetail();
}

function doSaveDetail() {
	var data = {
			id : $("#userId").val(),
			name : $("#userName").val(),
			account : $("#userAccount").val(),
			mobile : $("#userMobile").val(),
			organId : $("#userOrgan").data("id"),
			webAccessAllowed:$(":radio[name=userWebAccessAllowed]:checked").val(),
			mobileAccessAllowed:$(":radio[name=userMobileAccessAllowed]:checked").val(),
			description : $("#userDesc").val()
		};
	
	block("#detailForm");
	$.ajax({
		type: "POST",
		url: "save.json",
		data: data,
		dataType: "json",
		success: saveSucceedCallback,
		error:function(message){
			unblock("#detailForm");
			$.alert(message);
		}
	});
}

function saveSucceedCallback(data) {
	unblock("#detailForm");
	if (!data.succeed) {
		$.notice(data.message);
		return;
	}

	$("#userId").val(data.data.id);
	if (editAction = "new") {
		window.location.href = "edit.do?id="+data.data.id;
		$.info("保存成功！");
	}
	else {
		$.notice("保存成功！");
	}
}

$(document).ready(function() {
	$("#tabs").tab("show");
	$("#userOrgan").data("id",$("#userOrganId").val());

	detailValidator = $("#detailForm").validate({
		rules: {
			userName:{required:true, maxlength:50},
			userAccount:{required:true, maxlength:50},
			userMobile:{digits:true, maxlength:11, minlength:11},
			userOrgan:{required:true},
			userDesc:{maxlength:255}
		},
		messages:{
			userName:{required:"请输入用户名"},
			userAccount:{required:"请输入用户登录账号名"},
			userMobile:{digits: "手机号码是11位数字", maxlength:"手机号码是11位数字", minlength:"手机号码是11位数字"},
			userOrgan:{required:"请选择所属组织机构"}
		}
	});
	$().maxlength();

});

</script>

<form id="detailForm" class="form-horizontal">
<input type="hidden" id="userId" value="${data.id}">
<input type="hidden" id="userOrganId" value="${data.organId}">
	<fieldset>
	<div class="control-group">
		<label for="userName"  class="control-label">姓名：</label>
		<div class="controls">
		<input type="text" id="userName" name="userName" class="required" maxlength="50" value="${data.name}"> <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="userAccount" class="control-label">登录账号：</label>
		<div class="controls">
		<input type="text" id="userAccount" name="userAccount" class="required" maxlength="50" value="${data.account}"> <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="userMobile" class="control-label">手机号码：</label>
		<div class="controls">
		<input type="text" id="userMobile" name="userMobile" maxlength="11" value="${data.mobile}">
		</div>
	</div>
	<div class="control-group">
		<label for="userExecOrgan" class="control-label">组织机构：</label>
		<div class="controls">
		<input type="text" id="userOrgan" readonly="readonly" name="userOrgan" value="${data.organName}">
		<input type="button" class="btn" value="选择" onclick="selectOrganization()"> <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="userWebAccessAllowed" class="control-label">Web访问权限：</label>
		<div class="controls">
		<input type="radio" name="userWebAccessAllowed" value="true" ${data.webAccessAllowed?'checked=checked':''}>允许
		<input type="radio" name="userWebAccessAllowed" value="false" ${data.webAccessAllowed?'':'checked=checked'}>不允许
		</div>
	</div>
		<div class="control-group">
		<label for="userMobileAccessAllowed" class="control-label">手机访问权限：</label>
		<div class="controls">
		<input type="radio" name="userMobileAccessAllowed" value="true" ${data.mobileAccessAllowed?'checked=checked':''}>允许
		<input type="radio" name="userMobileAccessAllowed" value="false" ${data.mobileAccessAllowed?'':'checked=checked'}>不允许
		</div>
	</div>
	<div class="control-group">
		<label for="userDesc" class="control-label">描述：</label>
		<div class="controls">
		<textarea id="userDesc" name="userDesc" maxlength="255">${data.description}</textarea>
		</div>
	</div>
	<div class="form-actions">
		<a href="#" class="btn btn-primary" onclick="saveDetail()"><i class="icon-ok"></i>保存</a>
	</div>
	</fieldset>
</form>
